package com.combetter.changxing.mine;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.combetter.changxing.R;
import com.combetter.changxing.base.BaseActivity;
import com.combetter.changxing.bean.MessageBean;
import com.combetter.changxing.view.CancelOrOkDialog;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.MultiItemTypeAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @author Vany Liu
 * e-mail liu1281781414@outlook.com
 * Created ${date} ${time}
 * description :
 **/
public class MessageActivity extends BaseActivity {
    @Bind(R.id.tv_title_name)
    TextView tvTitleName;
    @Bind(R.id.iv_back)
    ImageView ivBack;
    @Bind(R.id.iv_right)
    ImageView ivRight;
    @Bind(R.id.iv_right_add)
    ImageView ivRightAdd;
    @Bind(R.id.actionbar)
    Toolbar actionbar;
    @Bind(R.id.rv_message)
    RecyclerView rvMessage;

    List<MessageBean> list = new ArrayList<>();
    private CommonAdapter commonAdapter;

    @Override
    protected int layoutId() {
        return R.layout.activity_message;
    }


    @Override
    protected void initViews() {
        tvTitleName.setText("我的消息");
        ivRight.setVisibility(View.GONE);
        rvMessage.setLayoutManager(new LinearLayoutManager(this));
    }

    @Override
    protected void loadData() {
        list.add(new MessageBean("欢迎加入畅行", "10-1"));
        list.add(new MessageBean("新型加热不燃烧烟具已上市", "10-1"));
        list.add(new MessageBean("新型烟油-薄荷味，现已登录京东商城", "10-1"));
        list.add(new MessageBean("新型烟油-薄荷味，现已登录淘宝", "09-28"));
        commonAdapter = new CommonAdapter<MessageBean>(this, R.layout.item_message, list) {

            @Override
            protected void convert(ViewHolder holder, MessageBean messageBean, int position) {
                holder.setText(R.id.tv_item_context, messageBean.getContext());
                holder.setText(R.id.tv_item_time, messageBean.getTime());
                holder.setOnClickListener(R.id.ll_item_message, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        CancelOrOkDialog dialog = new CancelOrOkDialog(mContext, messageBean.getContext()) {
                            @Override
                            public void ok() {
                                super.ok();
                                dismiss();
                            }
                        };
                        dialog.setCancelable(true);
                        dialog.show();
                    }
                });
            }
        };
        rvMessage.setAdapter(commonAdapter);

        commonAdapter.notifyDataSetChanged();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick(R.id.iv_back)
    public void onViewClicked() {
        finish();
    }


}
